home *** CD-ROM | disk | FTP | other *** search
- Path: ibm32.perftech.com!usenet
- From: murf@perftech.com (John Murphy)
- Newsgroups: comp.lang.c
- Subject: Re: reversing a string
- Date: 8 Apr 1996 12:47:03 GMT
- Organization: Performance Technology Inc
- Message-ID: <4kb1s7$6eu@ibm32.perftech.com>
- References: <4k6cjl$j8f@central.server.swt.edu>
- NNTP-Posting-Host: k5zba.perftech.com
- Mime-Version: 1.0
- NNTP-Posting-User: REVCO
- X-Newsreader: WinVN 0.93.11
-
- In article <4k6cjl$j8f@central.server.swt.edu>, ln16674@nyssa.swt.edu
- says...
- >
- >I have a challenge from a friend of mine. He wanted me to reverse a string
- >with recursion without using any additional variables or loops. I got mine
- >to work by using exclusive or, but I needed an additional variable. Can
- >someone help with this problem without using the additional variable?
- >
- >Thanks
- You can swap two variables, x and y, with the following series of exclusive
- or's:
- x ^= y;
- y ^= x;
- x ^= y;
-
- Or if you favor compactness over readability, you can use:
-
- x ^= y ^= x ^x y;
-
- Murf
-
-